package cn.maihe.elg.operation.supports.electronicseal.kt.cloudsign.service;

import cn.maihe.elg.operation.model.dto.InnerBaseResp;
import cn.maihe.elg.operation.supports.electronicseal.kt.KtConfig;
import cn.maihe.elg.operation.supports.electronicseal.kt.cloudsign.BaseKtCloudSignService;
import cn.maihe.elg.operation.supports.electronicseal.kt.cloudsign.dto.ContractGetUrlReqDTO;
import cn.maihe.elg.operation.supports.electronicseal.kt.cloudsign.dto.ContractGetUrlRespDTO;
import cn.maihe.elg.operation.supports.electronicseal.kt.cloudsign.enums.CloudSignInterfaceEnum;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description
 * @Author WJH
 * @Date 2022/09/07
 */
@Service
@Slf4j
public class ContractGetUrlService extends BaseKtCloudSignService<ContractGetUrlReqDTO, ContractGetUrlRespDTO> {
    public ContractGetUrlService(KtConfig ktConfig) {
        super(ktConfig);
    }

    @Resource
    private ElgResourceService elgResourceService;

    @Override
    protected CloudSignInterfaceEnum serviceName() {
        return CloudSignInterfaceEnum.contractGetUrl;
    }

    @Override
    public InnerBaseResp<?> doRequest(String traceId, ContractGetUrlReqDTO reqDTO) {
        return super.doRequest(traceId, reqDTO);
    }

    public ContractGetUrlRespDTO getContractSignUrl(String traceId, String acceptOrderNo, String bidderCreditCode, String sid) {
        String succUrl = elgResourceService.buildElgFrontUrl("/#/signSuc?order=" + acceptOrderNo);
        String backUrl = elgResourceService.buildElgFrontUrl("/#/signFail?order=" + acceptOrderNo);
        ContractGetUrlReqDTO reqDTO = ContractGetUrlReqDTO.build(sid, bidderCreditCode, succUrl, backUrl);
        InnerBaseResp innerBaseResp = this.doRequest(traceId, reqDTO);
        ContractGetUrlRespDTO respDTO = this.parseInnerBaseResp(innerBaseResp);
        return respDTO;
    }
}
